//
//  ZHBaseViewController.m
//  LoveFreshBee
//
//  Created by brice Mac on 2016/10/17.
//  Copyright © 2016年 王忠迪. All rights reserved.
//

#import "ZHBaseViewController.h"
#import "ZHSettingButton.h"

@interface ZHBaseViewController ()<UITableViewDataSource,UITableViewDelegate>

<<<<<<< HEAD
@property(nonatomic,weak)UINavigationBar *navBar;

@property(nonatomic,strong)UINavigationItem *navItem;

@property(nonatomic,weak)UITableView *tableView;

=======
>>>>>>> 2ad6dfbb82c5ee29fcdd5764696611e08476f062
@end

@implementation ZHBaseViewController


- (UINavigationItem *)navItem {
    if (_navItem == nil) {
        UINavigationItem *navItem = [[UINavigationItem alloc]init];
        _navItem = navItem;
    }
    return _navItem;
}

<<<<<<< HEAD
- (void)loadView {
    [super loadView];
    
    [self setupUI];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //这个属性的默认值是true,这让容器视图控制器知道他们应该调整滚动视图insets这个视图控制器的视图来占屏幕区域被一个状态栏,搜索栏,导航栏,工具栏,或标签栏。
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)setupUI {
    //初始化tableView
    [self setupTableView];
    //初始化导航栏
    [self setupNavBar];
=======


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化tableView
    [self setupTableView];
    
    //初始化导航栏
    [self setupNavBar];
    
    self.view.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
    //这个属性的默认值是true,这让容器视图控制器知道他们应该调整滚动视图insets这个视图控制器的视图来占屏幕区域被一个状态栏,搜索栏,导航栏,工具栏,或标签栏。
    self.automaticallyAdjustsScrollViewInsets = NO;
>>>>>>> 2ad6dfbb82c5ee29fcdd5764696611e08476f062
}

- (void)setupNavBar {
    
    UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
    _navBar = navBar;

    //1、设置导航条 navBar.items 数据源为 @[self.navItem] 数组
    //2、子类中需要调用 self.navgationItem.titleView/leftBarbuttonitem/rightBarbuttonItem 即可以显示控件
    navBar.items = @[self.navItem];
    //    [self.navBar pushNavigationItem:self.navItem animated:YES];
    
    [self.view addSubview:navBar];
    
    ZHSettingButton *leftBtn = [[ZHSettingButton alloc]initWithTitle:@"" image:[UIImage imageNamed:@"v2_goback"] target:self actionName:@selector(backToFront)];
    
    self.navItem.leftBarButtonItem = leftBtn;
    
<<<<<<< HEAD

=======
>>>>>>> 2ad6dfbb82c5ee29fcdd5764696611e08476f062
}
- (void)backToFront {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupTableView {
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
<<<<<<< HEAD
=======
    
    tableView.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
    
>>>>>>> 2ad6dfbb82c5ee29fcdd5764696611e08476f062
    _tableView = tableView;
    [self.view addSubview:tableView];
    tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0);
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
<<<<<<< HEAD
    self.tableView.tableFooterView = [[UIView alloc]init];
}


/**
 去掉基类中的数据源方法，因为他有时候会导致子类的数据源方法不执行
 
=======
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navBar.translucent = NO;
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    self.navBar.translucent = YES;
}

/**
  如果去掉基类中的数据源方法，子类中也没有实现，加载tableView会报错
>>>>>>> 2ad6dfbb82c5ee29fcdd5764696611e08476f062
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
<<<<<<< HEAD
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BaseCellId" forIndexPath:indexPath];
=======
    UITableViewCell *cell = [[UITableViewCell alloc]init];
>>>>>>> 2ad6dfbb82c5ee29fcdd5764696611e08476f062
    return cell;
}


@end



